﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using mock_ehr_lib.Data;
using mock_ehr_lib.Model;

namespace mock_ehr_lib.View
{
    public partial class PatientSearch : Form
    {
        public Patient SelectedPatient { get; private set; }

        public PatientSearch()
        {
            InitializeComponent();
            Load += loaded;
            dgvAllPatients.MouseDoubleClick += patientSelected;
        }

        void patientSelected(object sender, MouseEventArgs e)
        {
            if (dgvAllPatients.SelectedRows.Count != 1) return;
            var selectedRow = dgvAllPatients.SelectedRows[0];
            SelectedPatient = selectedRow.DataBoundItem as Patient;
            Close();
        }

        void loaded(object sender, EventArgs e)
        {
            dgvAllPatients.DataSource = MockEHRApplication.Instance.PatientRepository.GetAllPatients();
        }
    }
}
